<template>
  <div class="uph">
    <el-row :style="{paddingBottom: 0}">
      <el-col>
        <dynForm :info-form="infoForm" :search-tags="searchTags" :select-list="selectList" label-width="120px">
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="doSearch">
            {{ $t("search") }}
          </el-button>
        </dynForm>
      </el-col>
    </el-row>
    <div class="echart-box">
      <uphChart />
    </div>
    <el-card shadow="never">
      <el-row>
        <dynTable
          ref="dynTable"
          :loading="tableLoading"
          :table-data="tableData"
          :table-columns="tableColumns"
        />
      </el-row>
    </el-card>
  </div>
</template>

<script>
import mySetting from '@/mixins/mySetting'
import dashboardMagApi from '@/api/dashboardManager/binAnalysis'
import enumApi from '@/api/system/enum'
import uphChart from './components/mix-line-bar.vue'
import { mapGetters } from 'vuex'
export default {
  name: 'Uph',
  components: { uphChart },
  mixins: [mySetting],
  data() {
    return {
      outputTypeName: '',
      infoForm: {},
      searchTags: [
        { label: this.$t('processFlow'), prop: 'Processflow', tag: 'DynInput' },
        { label: this.$t('handlerId'), prop: 'HandlerId', tag: 'DynInput' },
        { label: this.$t('packageType'), prop: 'Package', tag: 'DynInput' },
        { label: this.$t('productName'), prop: 'ProductModel', tag: 'DynInput' },
        { label: this.$t('OutputType'), prop: 'OutPutType', tag: 'DynSelect', translate: true },
        { label: this.$t('timeInterval'), prop: '', tag: 'Dyndaterange', event: (value) => {
          this.infoForm.startTime = Array.isArray(value) ? value[0] : null
          this.infoForm.endTime = Array.isArray(value) ? value[1] : null
        } }
      ],
      selectList: {},
      tableLoading: true,
      tableColumns: [
        { prop: '', label: this.$t('index'), type: 'index', width: '50px', templete: (_scope) => {
          return (
            <span>{ (this.listQuery.page - 1) * this.listQuery.size + _scope.$index + 1 }</span>
          )
        } },
        { prop: 'outputValue', label: this.$t('OutputType') },
        { prop: 'stepType', label: this.$t('stepType') },
        { prop: 'totalUph', label: this.$t('totalUph') },
        { prop: 'goalUph', label: this.$t('goalUph') }
      ]
    }
  },
  computed: {
    ...mapGetters(['baseApi'])
  },
  watch: {},
  created() {
    this.initList()
    this.getCategoryList()
  },
  mounted() {

  },
  methods: {
    // 表单项类型
    async getCategoryList() {
      const res = await enumApi.getList({ enumName: 'UphOutputTypeEnum' })
      this.$set(this.selectList, 'OutPutType', res.data)
    },
    // 初始化列表
    async initList() {
      const res = await dashboardMagApi.getUPHList(this.$clearNull(this.infoForm))
      this.tableData = res.data
      this.tableLoading = false
      // this.$nextTick(() => {
      //   this.editEchart(res.data)
      // })
    },
    doSearch() {
      this.initList()
    },
    async exportData() {
      const res = await dashboardMagApi.getUPHList(this.$clearNull({ ...this.infoForm, ...this.listQuery, toexcel: 1 }))
      // window.location.href = this.baseApi + '/' + res.data
      window.open(this.baseApi + '/' + res.data)
    }
  }
}
</script>

<style scoped lang="scss">
@import "~@/assets/styles/defaultStyle.scss";
.echart-box{
  width: 100%;
  height: 400px;
  background-color: #fff;
}
</style>
